package cn.hadron.ssh.dao.impl;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import cn.hadron.ssh.bean.Channel;
import cn.hadron.ssh.dao.*;

public class ChannelDaoImpl implements ChannelDao{
	private SessionFactory sessionFactory;
	private Session session;
	@Override
	public List<Channel> findAll(){
		List<Channel> list=getSession().createQuery("from Channel",Channel.class).list();
		return list;
	}
	@Override
	public Channel load(int id) {
		return (Channel)getSession().load(Channel.class, id);
	}
	@Override
	public void add(Channel c){
		getSession().save(c);
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	public Session getSession() {
		if (null == session || false == session.isOpen())
			session = sessionFactory.openSession();
		return session;
	}
	public void setSession(Session session) {
		this.session = session;
	}
}
